<template>
	<view>
		<cu-custom :bgColor="bgColor" :isBack="true">
			<block slot="backText"></block>
			<block slot="content">派工详情</block>
		</cu-custom>
		<form>
			<view class="uni-list">
				<view class="cu-form-group">
					<text class="title">单号</text>
					<view class="txt">87212352</view>
				</view>
				<view class="cu-form-group">
				<picker @change="bindTypeChange" :value="indexType" :range="typePickerList">
					<view class="cu-form-group">
						<text class="title" style="margin-left: -30rpx;">组别</text>
						<text class="txt">{{typePickerList[indexType]}}</text>
					</view>
				</picker>
				</view>
				<view class="cu-form-group">
					<text class="title">指令单号</text>
					<view class="txt">87212352</view>
				</view>
				<view class="cu-form-group">
					<text class="title">货号</text>
					<view class="txt">87212352</view>
				</view>
				<view class="cu-form-group">
					<text class="title">颜色</text>
					<view class="txt">黑BLACK</view>
				</view>
				<view class="cu-form-group">
					<text class="title">批次</text>
					<view class="txt">1</view>
				</view>
				<view class="cu-form-group">
					<text class="title">工序</text>
					<view class="txt">87212352</view>
				</view>
				<view class="cu-form-group">
				<picker @change="depositoryChange" :value="depositoryType" :range="depository">
					<view class="cu-form-group">
						<text class="title" style="margin-left: -30rpx;">仓库</text>
						<text class="txt">{{depository[depositoryType]}}</text>
					</view>
				</picker>
				</view>
			</view>
			
			<!-- 表格 -->
			<view>
				<view class="uni-container">
					<uni-table ref="table" :loading="loading" border stripe type="selection" emptyText="暂无更多数据" @selection-change="selectionChange">
						<uni-tr>
							<uni-th width="70" align="center">尺码</uni-th>
							<uni-th width="70" align="center">冲刀</uni-th>
							<uni-th width="75" align="center">待派工数</uni-th>
							<uni-th width="75" align="center">已派工数</uni-th>
							<uni-th width="80" align="center">人员/数量</uni-th>
						</uni-tr>
						<uni-tr v-for="(item, index) in tableData" :key="index">
							<uni-td>{{ item.size }}</uni-td>
							<uni-td>
								<view class="name">{{ item.name }}</view>
							</uni-td>
							<uni-td align="center">{{ item.pNo }}</uni-td>
							<uni-td align="center">
								<input @click="inputDialogToggle(item.pdNo)" :value="item.pdNo" style="background-color: antiquewhite;">
								</input>
							</uni-td>
							<uni-td>
								<view class="uni-group">
									<button class="uni-button" size="mini" type="primary" @click="goPeople()">选人</button>
								</view>
							</uni-td>
						</uni-tr>
						<view>
							<!-- 输入框示例 -->
							<uni-popup ref="inputDialog" type="dialog">
								<uni-popup-dialog ref="inputClose"  mode="input" title="派工人数" :value="item.pdNo"
									placeholder="请输入派工人数" @confirm="dialogInputConfirm()"></uni-popup-dialog>
							</uni-popup>
						</view>
					</uni-table>
				</view>
			</view>
		</form>
	</view>
</template>

<script>
	import tableData from '@/api/tableData.js'
	export default {
		data() {
			return {
				moren:0,
				indexType:1,
				typePickerList: [1,2,3,4],
				depository: ["泉州","厦门","漳州","莆田"],
				depositoryType:1,
				bgColor: 'bg-green',
				searchVal: '',
				tableData: [],
				// 每页数据量
				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				loading: false
			}
		},
		onLoad() {
				this.selectedIndexs = []
				this.getData(1)
			},
		methods: {
			bindTypeChange(e) {
				this.indexType = e.target.value
			},
			depositoryChange(e) {
				this.depositoryType = e.target.value
			},
			inputDialogToggle(e) {
				this.moren = e
				this.$refs.inputDialog.open()
			},
			dialogInputConfirm(val) {
				console.log(val)
				this.$refs.inputDialog.close()
			},
			// 多选处理
			selectedItems() {
				return this.selectedIndexs.map(i => this.tableData[i])
			},
			// 多选
			selectionChange(e) {
				console.log(e.detail.index)
				this.selectedIndexs = e.detail.index
			},
			// 获取数据
			getData(pageCurrent, value = '') {
				this.loading = true
				this.pageCurrent = pageCurrent
				this.request({
					pageSize: this.pageSize,
					pageCurrent: pageCurrent,
					value: value,
					success: res => {
						this.tableData = res.data
						this.total = res.total
						this.loading = false
					}
				})
			},
			// 伪request请求
			request(options) {
				const { pageSize, pageCurrent, success, value } = options
				let total = tableData.length
				let data = tableData.filter((item, index) => {
					const idx = index - (pageCurrent - 1) * pageSize
					return idx < pageSize && idx >= 0
				})
				if (value) {
					data = []
					tableData.forEach(item => {
						if (item.name.indexOf(value) !== -1) {
							data.push(item)
						}
					})
					total = data.length
				}
	
				setTimeout(() => {
					typeof success === 'function' &&
						success({
							data: data,
							total: total
						})
				}, 500)
			},
			goPeople(){
				uni.navigateTo({
					url:'/pages/mcloud/dcDispatchPeople'
				})
			}
		}
	}
</script>

<style>
.cu-form-group {
		width: 100%;
		background-color: #ffffff;
		padding: 1upx 30upx;
		display: flex;
		align-items: center;
		min-height: 100upx;
		justify-content: space-between;
		
	}
	.uni-group {
		display: flex;
		align-items: center;
	}
</style>
